package org.scboy.common.dynamic.node.serviceNode;

import java.util.List;

import org.scboy.common.annotation.ScriptNode;
import org.scboy.common.beans.DynamicServiceResult;
import org.scboy.common.dynamic.node.BaseNode;
import org.scboy.utils.entitys.coobi.Model;

import cn.hutool.json.JSONObject;

@ScriptNode(value="SERVICE_RETURN")
public class ServiceReturnNode extends BaseNode {

	@Override
	public void create(JSONObject object) {
		
	}

	@SuppressWarnings("unchecked")
	@Override
	public Object run() {
		/**
		 * 测试日志
		 */
		if(this.script.isTest()) {
			this.script.appendMsg("----->开始执行："+getNodeName()+" 节点ID："+this.getId());
		}
		
		Object data=getSourceData("data", true, Object.class);
		
		DynamicServiceResult result=new DynamicServiceResult();
		
		if(data instanceof List<?>) {
			result.setList((List<Model>)data);
		}else if(data instanceof Model) {
			result.setEntity((Model)data);
		}
		
		/**
		 * 测试日志
		 */
		if(this.script.isTest()) {
			this.script.appendMsg("返回值：\r\n"+entityToString(result));
		}
		
		return result;
	}
}
